﻿using System;
using System.Xml;

namespace Devv.FreshTracker.Entity
{
	[Serializable]
	public class Project
	{
		#region Properties

		public Int64 Id { get; set; }
		public String Name { get; set; }
		public Client Client { get; set; }

		public String DisplayMember
		{
			get { return ToString(); }
		}

		#endregion

		#region Constructor

		public Project()
		{
			Client = new Client();
		}

		public Project(XmlNode node)
		{
			XmlNamespaceManager ns = new XmlNamespaceManager(node.OwnerDocument.NameTable);
			ns.AddNamespace("ns", FreshBooks.DEFAULT_XMLNS);

			Id = Convert.ToInt64(node.SelectSingleNode("ns:project_id", ns).InnerText);
			Name = node.SelectSingleNode("ns:name", ns).InnerText;

			Client = new Client();

			String clientId = node.SelectSingleNode("ns:client_id", ns).InnerText;

			if (!String.IsNullOrEmpty(clientId))
			{
				Client.Id = Convert.ToInt64(clientId);
			}
		}

		#endregion

		#region ToString

		public override String ToString()
		{
			return Name + "(" + Client.DisplayMember + ")";
		}

		#endregion
	}
}